package com.hllxd.hism.star.basic.service.service;

import com.hllxd.hism.star.basic.service.dao.mapper.doris.HealthScoreMapper;
import com.hllxd.hism.star.basic.service.model.doris.HealthScoreAppidEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lixiyong01
 * @date 2023.04.02
 * 健康分管理
 */
@Slf4j
@Service("healthScoreService")
public class HealthScoreServiceImpl implements HealthScoreService {

//    @Autowired
//    TblStorageHealthScoreMapper storageHealthScoreMapper;

    @Autowired
    HealthScoreMapper healthScoreMapper;

    public static String DEFAULT_ALL = "0";


    @Override
    public List<HealthScoreAppidEntity> listHealthScoreAppid(String dt, String dt2, String tag, String ownerId, String appId, String orgCnName) {
        log.info("param: {}, {}, {}, {}, {}.", dt, dt2, tag, ownerId, appId);
        if (StringUtils.isEmpty(ownerId) || ownerId.equals(DEFAULT_ALL)) {
            ownerId = null;
        }
        if (StringUtils.isEmpty(orgCnName) || orgCnName.equals(DEFAULT_ALL)) {
            orgCnName = null;
        } else {
            orgCnName = "%" + orgCnName.trim() + "%";
        }
        String typeCode;
        if ("store".equals(tag)) {
            typeCode = "存储白名单";
        } else {
            typeCode = "计算白名单";
        }
        return healthScoreMapper.listHealthScoreAppid(dt, dt2, tag, ownerId, appId, orgCnName, typeCode);
    }

//    @Override
//    public List<TblStorageHealthScore> listAllTableScore(String dt, String dt2, String ownerId, String orgCn, String hasScore) {
//
//        TblStorageHealthScore healthScore = new TblStorageHealthScore();
//
//
//        if (!"".equals(dt) && dt != null) {
//            healthScore.setStartDt(dt.replaceAll("-", ""));
//        } else {
//            healthScore.setStartDt(LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMdd")));
//        }
//        if (!"".equals(dt2) && dt2 != null) {
//            healthScore.setEndDt(dt2.replaceAll("-", ""));
//        } else {
//            healthScore.setEndDt(LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMdd")));
//        }
//
//        if (!"".equals(ownerId) && ownerId != null) {
//            healthScore.setOwnerId(ownerId);
//        }
//        if (!"".equals(orgCn) && orgCn != null) {
//            healthScore.setOrgCnName(orgCn);
//        }
//
//        if (!"".equals(hasScore) && hasScore != null) {
//            healthScore.setExistHealthScore(hasScore);
//        } else {
//            healthScore.setExistHealthScore("true");
//        }
//
//        return storageHealthScoreMapper.selectTabHealthScore(healthScore);
//    }

//    @Override
//    public List<TblStorageHealthScore> listGroupHealthScore(String group, String dt, String dt2, String ownerId, String orgCn) {
//
//        // 日期格式化处理
//        if (!"".equals(dt) && dt != null) {
//            dt = dt.replaceAll("-", "");
//        } else {
//            dt = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMdd"));
//        }
//        if (!"".equals(dt2) && dt2 != null) {
//            dt2 = dt2.replaceAll("-", "");
//        } else {
//            dt2 = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMdd"));
//        }
//
//        return storageHealthScoreMapper.listGroupHealthScore(group, dt, dt2, ownerId, orgCn);
//    }


//    @Override
//    public TblStorageHealthScore getStorageHealthScoreDetail(String tableName, String dt) {
//        TblStorageHealthScoreExample healthScoreExample = new TblStorageHealthScoreExample();
//        TblStorageHealthScoreExample.Criteria criteria = healthScoreExample.createCriteria();
//        criteria.andTableNameEqualTo(tableName);
//        criteria.andDtEqualTo(dt);
//
//        List<TblStorageHealthScore> tblStorageHealthScores = storageHealthScoreMapper.selectByExample(healthScoreExample);
//        if (tblStorageHealthScores != null && tblStorageHealthScores.size() > 0) {
//            return tblStorageHealthScores.get(0);
//        } else {
//            return null;
//        }
//    }

}
